<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style type="text/css">
        .lunbo {
            width: 900px;
            height: 400px;
            margin: 100px auto;
        }

        .lunbo img {
            width: 100%;
            height: 100%;
        }
    </style>
</head>

<body>
    <!--轮播图模块 -->
    <div class="lunbo">
        <img id="lunbo_img" src="../img/pic3.jpg">
    </div>
    
</body>
<script>
// Js代码
    var index = 1;
      function lunbo(){
          index ++ ;
          //判断index是否大于3
          if(index > 3){
              index = 1;
          }
          //获取img对象
          var img = document.getElementById("lunbo_img");
          img.src = "../img/pic"+index+".jpg";
      }
      //2.定义定时器
      setInterval(lunbo,2000);
    //   切记定时器里调用lunbo方法不能加(),setInterval(lunbo,2000);如果加()会执行lunbo()方法，而导致定时器没用。
  </script>
</html>